﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Motions
{
 public abstract class Motions
    {

        /// <summary>
        /// 判断卡是否启用成功或初始化成功
        /// </summary>
        protected bool m_bEnable = false;

        /// <summary>
        /// 当前卡在系统中的索引号 卡号
        /// </summary>
        protected int m_nCardIndex = 0;

        /// <summary>
        /// 卡类型名
        /// </summary>
        private string m_strName = string.Empty;

        /// <summary>
        /// 卡类型支持的最小轴号
        /// </summary>
        private int m_nMinAxisNo = 0;

        /// <summary>
        /// 卡支持的最大轴号
        /// </summary>
        private int m_nMaxAxisNo = 16;
        /// <summary>
        /// 轴卡初始化成功
        /// </summary>
        public bool CardIniOK = false;

        public Motions(int CardNo, string strName,int MinAxisNo,int MaxAxisNo)
        {
            this.m_bEnable = false;
            m_nCardIndex = CardNo;//卡号
            m_strName = strName;//卡名称
            m_nMaxAxisNo = MaxAxisNo;//最大轴号
            m_nMinAxisNo = MinAxisNo;//最小轴号
        }

        /// <summary>
        /// 轴卡初始化
        /// </summary>
        /// <returns></returns>
        public abstract void InitMotionCard();

        /// <summary>
        /// 轴卡反初始化
        /// </summary>
        /// <returns></returns>
        public abstract void DeInitMotionCard();

        /// <summary>
        /// 按位获取输入信号
        /// </summary>
        /// <param name="nIndex">点位号</param>
        /// <returns></returns>
        public abstract bool ReadIn(int nCardN0,int nIndex);

        /// <summary>
        /// 按位获取输出信号
        /// </summary>
        /// <param name="nIndex"></param>
        /// <returns></returns>
        public abstract bool ReadOut(int nCardN0, int nIndex);

        /// <summary>
        /// 按位输出信号
        /// </summary>
        /// <param name="nIndex">点位号</param>
        /// <param name="bBit">rTrue False</param>
        /// <returns></returns>
        public abstract void WriteOut(int nCardN0, int nIndex, bool bBit);

        /// <summary>
        /// 开启使能
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <returns></returns>
        public abstract void ServoOn(int nAxisNo);

        /// <summary>
        /// 断开使能
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <returns></returns>
        public abstract void ServoOff(int nAxisNo);

        /// <summary>
        /// 轴清除报警
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract void ClearAxisAlarm(int nAxisNo);

        /// <summary>
        /// 位置清零
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <returns></returns>
        public abstract void SetPosZero(int nAxisNo);

        /// <summary>
        /// 轴正常停止
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <returns></returns>
        public abstract void StopAxis(int nAxisNo);

        /// <summary>
        /// 轴急停
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <returns></returns>
        public abstract void EmgAxis(int nAxisNo);

        /// <summary>
        /// 获取轴的编码器位置
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <returns></returns>
        public abstract double GetAxisActPos(int nAxisNo);

        /// <summary>
        /// 获取轴的规划位置
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract double GetAxisPrfPos(int nAxisNo);

        /// <summary>
        /// 获取轴使能信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetAxisSeverOn(int nAxisNo);

        /// <summary>
        /// 获取轴报警信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetAxisAlarm(int nAxisNo);

        /// <summary>
        /// 获取轴忙信号 ,false是空闲中
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetAxisBusy(int nAxisNo);

        /// <summary>
        /// 伺服运行到位信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetAxisDone(int nAxisNo);

        /// <summary>
        /// 伺服运行准备完成信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetAxisReady(int nAxisNo);

        /// <summary>
        /// 获取轴原点信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetAxisHome(int nAxisNo);

        /// <summary>
        /// 获取轴正限位信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetPosLimit(int nAxisNo);

        /// <summary>
        /// 获取轴负限位信号
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract bool GetNegLimit(int nAxisNo);

        /// <summary>
        /// 绝对位置移动
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <param name="nPos">位置</param>
        /// <param name="nSpeed">速度</param>
        /// <returns></returns>
        public abstract void AbsMove(int nAxisNo, double Pos, double Speed);

        /// <summary>
        /// 相对位置移动
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <param name="nPos">位置</param>
        /// <param name="nSpeed">速度</param>
        /// <returns></returns>
        public abstract void RelMove(int nAxisNo, double Pos, double Speed);

        /// <summary>
        /// Jog运动
        /// </summary>
        /// <param name="nAxisNo">轴号</param>
        /// <param name="nSpeed">速度</param>
        /// <param name="bPositive">方向</param>
        /// <returns></returns>
        public abstract void JogMove(int nAxisNo, double Speed, bool MovDir);
     
        /// <summary>
        /// 回原点
        /// </summary>
        /// <param name="nAxisNo"></param>
        /// <returns></returns>
        public abstract void HomeMove(int nAxisNo, int MoveDir,uint HomeMode);
        public abstract bool HomeOK(int nAxisNo);

        /// <summary>
        /// 初始化扩展IO卡
        /// </summary>
        /// <returns></returns>
        public abstract void InitExtIoCard(int CarsNO);

        /// <summary>
        /// 关闭扩展IO卡
        /// </summary>
        public abstract void DeInitExtIoCard(int Card);
        /// <summary>
        /// 按位获取输入信号
        /// </summary>
        /// <param name="nIndex"></param>
        /// <returns></returns>
        public abstract bool ReadExtIn(int CardNo,int nIndex);

        /// <summary>
        /// 按位获取输出信号
        /// </summary>
        /// <param name="nIndex"></param>
        /// <returns></returns>
        public abstract bool ReadExtOut(int CardNo, int nIndex);

        /// <summary>
        /// 按位输出信号
        /// </summary>
        /// <param name="nIndex"></param>
        /// <returns></returns>
        public abstract void WriteExtOut(int CardNo, int nIndex, bool bBit);
    
           
        public abstract bool GetBusState();

        public abstract void ClearBusAlarm();

        public abstract bool HomeMove1(int nAxisNo, int MoveDir);

        public abstract void OpenCmd (int cardNum, ushort channel, uint dir);

        public abstract void CloseCmd(int cardNum, ushort channel);

        public abstract void SetCmdData(int cardNum, ushort channel, double[] data);

        public abstract int GetCmdFIFOCount(int cardNum, ushort channel);

        public abstract void SetCmdDO(int cardNum, ushort channel);

        public abstract void CloseCmdDO(int cardNum, ushort channel);

        public abstract void ResetCmd(int cardNum, ushort channel);

    }
}
